<?php


namespace app\admin\controller;


use think\facade\Filesystem;

class Image extends AdminBase {
    public function editUpload() {
        if (!$this->request->isPost()) {
            return show(config('status.error'), '请求不合法');
        }

        $file = $this->request->file('edit');
//        $filename = Filesystem::putFile('upload', $file);
        $filename = Filesystem::disk('public')->putFile('upload/image', $file);

        $filename = "/storage/" . $filename;
        if (!$filename) {
            return show(config('status.error'), '上传图片失败');
        }
        $imageUrl = $filename;
//        return show(config('status.success'), '上传图片成功', $imageUrl);
        $result = [
            'code' => 0,
            'msg' => "success",
            'data' => $filename
        ];
        return json($result);
    }

    public function bannerUpload() {
        if (!$this->request->isPost()) {
            return show(config('status.error'), '请求不合法');
        }
        $file = $this->request->file('file');
        $filename = Filesystem::disk('public')->putFile('upload/image', $file);
        $filename = "/storage/" . $filename;
        if (!$filename) {
            return show(config('status.error'), '上传图片失败');
        }
        $result = [
            'code' => 0,
            'msg' => "success",
            'data' => [
                'src' => $filename
            ]
        ];
        return json($result);
    }
}